package com.nanrui.mutualinductor.ui.service;


import com.nanrui.mutualinductor.communicate.PacketCallback;
import com.nanrui.mutualinductor.data.Packet_56;
import com.nanrui.mutualinductor.data.Packet_56_01;
import com.nanrui.mutualinductor.domains.CurrentTransformerViewInfo;
import com.nanrui.mutualinductor.domains.TraditionTransformerViewInfo;
import com.nanrui.mutualinductor.ui.page.DKActivity;

//CT传统法误差测试Service
public class TraditionTransformerService {
    private DKActivity activity;

    public TraditionTransformerService(DKActivity paramDKActivity) {
        this.activity = paramDKActivity;
    }

    /**
     * 显示数据
     *
     * @param traditionTransformerViewInfo
     * @param paramPacket_56_01
     */
    public void display(TraditionTransformerViewInfo traditionTransformerViewInfo, Packet_56_01 paramPacket_56_01) {
        //f u & r
        traditionTransformerViewInfo.setsPhaseError(Float.valueOf(paramPacket_56_01.getsPhaseError()));
        traditionTransformerViewInfo.setsQuadratureError(Float.valueOf(paramPacket_56_01.getsQuadratureError()));
        traditionTransformerViewInfo.setsWorkingVoltage(Float.valueOf(paramPacket_56_01.getsWorkingVoltage()));
        traditionTransformerViewInfo.setsSecondaryR(Float.valueOf(paramPacket_56_01.getsSecondaryR()));
        //表格数据
        traditionTransformerViewInfo.setsIErrors(paramPacket_56_01.getsIErrors());
        traditionTransformerViewInfo.setsIRoundErrors(paramPacket_56_01.getsIRoundErrors());
        traditionTransformerViewInfo.setsPhaseDisps(paramPacket_56_01.getsPhaseDisps());
        traditionTransformerViewInfo.setsPhaseRoundDisps(paramPacket_56_01.getsPhaseRoundDisps());

    }

    public TraditionTransformerViewInfo getDefaultViewInfo() {
        TraditionTransformerViewInfo traditionTransformerViewInfo = new TraditionTransformerViewInfo();
        traditionTransformerViewInfo.setmStatus((short) 1);
//        localCurrentTransformerViewInfo.setmRatedSecondary(5.0F);
//        localCurrentTransformerViewInfo.setmRatedPrimary(75.0F);
//        localCurrentTransformerViewInfo.setmGrade((short) 1);
//        localCurrentTransformerViewInfo.setmPhaseAngle(0.8F);
//        localCurrentTransformerViewInfo.setmRatedLoad(5.0F);
//        localCurrentTransformerViewInfo.setmMiniLoad(2.5F);
        return traditionTransformerViewInfo;
    }

    public void queryData(TraditionTransformerViewInfo traditionTransformerViewInfo, PacketCallback<Packet_56_01> paramPacketCallback) {
        Packet_56_01 localPacket_56_01 = new Packet_56_01();
        localPacket_56_01.setmFlag((short) 3);
        localPacket_56_01.setFrameNo((short) 01);
        localPacket_56_01.setmGrade(traditionTransformerViewInfo.getmGrade());
        localPacket_56_01.setmRatedPrimary(traditionTransformerViewInfo.getmRatedPrimary());
        localPacket_56_01.setmRatedSecondary(traditionTransformerViewInfo.getmRatedSecondary());
        localPacket_56_01.setmRatedLoad(traditionTransformerViewInfo.getmRatedLoad());
        localPacket_56_01.setmMiniLoad(traditionTransformerViewInfo.getmMiniLoad());
        localPacket_56_01.setmPhaseAngle(traditionTransformerViewInfo.getmPhaseAngle());
        this.activity.sendPacket(localPacket_56_01, paramPacketCallback);
    }

    public void resetResult(TraditionTransformerViewInfo traditionTransformerViewInfo) {
        traditionTransformerViewInfo.setsPhaseError(null);
        traditionTransformerViewInfo.setsQuadratureError(null);
        traditionTransformerViewInfo.setsWorkingVoltage(null);
        traditionTransformerViewInfo.setsSecondaryR(null);
        traditionTransformerViewInfo.setsIErrors(null);
        traditionTransformerViewInfo.setsIRoundErrors(null);
        traditionTransformerViewInfo.setsPhaseDisps(null);
        traditionTransformerViewInfo.setsPhaseRoundDisps(null);
        traditionTransformerViewInfo.setsResult(null);
    }


    public void startMeasure(TraditionTransformerViewInfo traditionTransformerViewInfo, PacketCallback<Packet_56_01> paramPacketCallback) {
        Packet_56_01 localPacket_56_01 = new Packet_56_01();
        localPacket_56_01.setmFlag((short) 1);
        localPacket_56_01.setFrameNo((short) 01);
        localPacket_56_01.setmGrade(traditionTransformerViewInfo.getmGrade());
        localPacket_56_01.setmRatedPrimary(traditionTransformerViewInfo.getmRatedPrimary());
        localPacket_56_01.setmRatedSecondary(traditionTransformerViewInfo.getmRatedSecondary());
        localPacket_56_01.setmRatedLoad(traditionTransformerViewInfo.getmRatedLoad());
        localPacket_56_01.setmMiniLoad(traditionTransformerViewInfo.getmMiniLoad());
        localPacket_56_01.setmPhaseAngle(traditionTransformerViewInfo.getmPhaseAngle());
        this.activity.sendPacket(localPacket_56_01, paramPacketCallback);
    }

    public void stopMeasure(TraditionTransformerViewInfo traditionTransformerViewInfo, PacketCallback<Packet_56_01> paramPacketCallback) {
        Packet_56_01 localPacket_56_01 = new Packet_56_01();
        localPacket_56_01.setmFlag((short) 4);
        localPacket_56_01.setFrameNo((short) 01);
        localPacket_56_01.setmGrade(traditionTransformerViewInfo.getmGrade());
        localPacket_56_01.setmRatedPrimary(traditionTransformerViewInfo.getmRatedPrimary());
        localPacket_56_01.setmRatedSecondary(traditionTransformerViewInfo.getmRatedSecondary());
        localPacket_56_01.setmRatedLoad(traditionTransformerViewInfo.getmRatedLoad());
        localPacket_56_01.setmMiniLoad(traditionTransformerViewInfo.getmMiniLoad());
        localPacket_56_01.setmPhaseAngle(traditionTransformerViewInfo.getmPhaseAngle());
        this.activity.sendPacket(localPacket_56_01, paramPacketCallback);
    }

    public void updateConfig(TraditionTransformerViewInfo traditionTransformerViewInfo, PacketCallback<Packet_56_01> paramPacketCallback) {
        Packet_56_01 localPacket_56_01 = new Packet_56_01();
        localPacket_56_01.setmFlag((short) 0);
        localPacket_56_01.setFrameNo((short) 01);
        localPacket_56_01.setmGrade(traditionTransformerViewInfo.getmGrade());
        localPacket_56_01.setmRatedPrimary(traditionTransformerViewInfo.getmRatedPrimary());
        localPacket_56_01.setmRatedSecondary(traditionTransformerViewInfo.getmRatedSecondary());
        localPacket_56_01.setmRatedLoad(traditionTransformerViewInfo.getmRatedLoad());
        localPacket_56_01.setmMiniLoad(traditionTransformerViewInfo.getmMiniLoad());
        localPacket_56_01.setmPhaseAngle(traditionTransformerViewInfo.getmPhaseAngle());
        this.activity.sendPacket(localPacket_56_01, paramPacketCallback);
    }
}

